import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { clearPending } from 'src/plugins/http/cancelToken';
import Home from '../views/Home.vue';

const routes: Array<RouteRecordRaw> = [
    {
        'path': '/',
        'name': 'Home',
        'component': Home,
        'redirect': '/articleList/:code',
        'children': [
            {
                'path': '/articleList/:code',
                'name': 'articleList',
                'meta': { 'title': '文章列表', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/article/list/index.vue')
            }, {
                'path': '/articleDetail/:topicId',
                'name': 'articleDetail',
                'meta': { 'title': '话题详情', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/article/detail/index.vue')
            }, {
                'path': '/add/:type/:id/:targetId',
                'name': 'add',
                'meta': { 'title': '发布页', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/add/index.vue')
            },
            {
                'path': '/my',
                'name': 'my',
                'meta': { 'title': '我的', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "my" */ '../views/my/index.vue')
            },
            {
                'path': '/myArticle',
                'name': 'myArticle',
                'meta': { 'title': '我的话题', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "my" */ '../views/my/myArticle/index.vue')
            },
            {
                'path': '/myComment&reply/:type',
                'name': 'myComment&reply',
                'meta': { 'title': '我的内容', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "my" */ '../views/my/myComment&reply/index.vue')
            },
            {
                'path': '/editorUser/:type',
                'name': 'editorUser',
                'meta': { 'title': '修改个人信息', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/my/editorUser/index.vue')
            },
            {
                'path': '/commentDetail/:commentId',
                'name': 'commentDetail',
                'meta': { 'title': '评论详情', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/reply/index.vue')
            }
        ]
    }
];

const router = createRouter({
    'history': createWebHashHistory(),
    routes
});

router.beforeEach((to, from) => {
    clearPending();
    return true;
});
router.afterEach((to, from) => true);

export default router;
